Assignment 6 - Spatial Analysis
Alex Cardelle
October 18, 2021
This map shows the spatial distribution of the U.S. population living in either a coupled opposite-sex or same-sex households. “Coupled” for this analysis means living in a household with either a married spouse or an unmarried partner present.
Unless otherwise noted, all information was collected from the 2019 American Community Survey (ACS 2019) through the Census API at http://data.census.gov.
Code Used to Generate Map
#load the variables
# B09019_010
# Estimated total population in households with an opposite-sex spouse present
# B09019_012
# Estimate total population in households with an opposite-sex unmarried partner present
# B09019_011
# Estimated total population in households with a same-sex spouse present
# B09019_013
# Estimate total population in households with a same-sex unmarried partner present
gay_hh <- get_acs(geography = "county", year = 2019, survey = "acs5",
variables = c(tot_het_ma = "B09019_010",tot_het_um = "B09019_012",
tot_gay_ma = "B09019_011", tot_gay_um = "B09019_013"),
output = "wide", geometry = TRUE)
#mutate the data to eliminate of the margin of error
gay_hh <- gay_hh %>%
select(-tot_het_maM, -tot_het_umM, -tot_gay_maM, -tot_gay_umM) %>%
filter(tot_het_maE > 0) %>%
mutate(pct_gay = round(100 * (tot_gay_maE + tot_gay_umE) / (tot_het_maE + tot_het_umE), 1))
#define the palette
household_palette <- colorNumeric(c("lightgrey", "darkblue"),
gay_hh$pct_gay)
#plot the map
gay_map <-
leaflet(gay_hh) %>%
addProviderTiles("Stamen.TonerLite") %>%
addPolygons(fillColor = ~household_palette(pct_gay), weight = 1, color = "grey", fillOpacity = 0.8,
highlightOptions = highlightOptions(fillColor = "yellow", fillOpacity = 0.9),
label = gay_hh$NAME,
popup = paste("Total population in coupled households: ", (gay_hh$tot_het_maE+gay_hh$tot_het_umE+gay_hh$tot_gay_maE+gay_hh$tot_gay_umE), "<br/>",
"Total population in coupled same-sex households: ",
(gay_hh$tot_gay_maE+gay_hh$tot_gay_umE), " (",
gay_hh$pct_gay, "%)",sep = "")) %>%
addLegend("bottomright", pal = household_palette, values = ~pct_gay,
title = "Percent of the U.S. population<br/> in households living in<br/>same-sex households",
labFormat = labelFormat(suffix = "%"),
opacity = 1)
Interactive Map